<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>东单办公系统-部门新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="media/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-container" style="margin-top: 5px">
    <form class="layui-form" action="" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">学科名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="name" autocomplete="off"
                       placeholder="请输入学科名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">成立日期</label>
            <div class="layui-input-block">
                <input type="text" name="createtime" id="date" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学科周期</label>
            <div class="layui-input-block">
                <input type="number" name="week" lay-verify="name"
                       autocomplete="off" placeholder="请输入学科周期" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学科类型</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required">
                    <option value=""></option>
                    <option value="1">普通版</option>
                    <option value="2">GP</option>
                    <option value="3">混合学科</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </form>
</div>


<script src="media/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(
        ['form', 'laydate'],
        function () {
            var form = layui.form, layer = layui.layer, laydate = layui.laydate,
                $ = layui.jquery;
            //日期
            laydate.render({
                elem: '#date'
            });

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                content: function (value) {
                    layedit.sync(editIndex);
                }
            });


            /*//监听提交
            form.on('submit(demo1)', function(data){
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });*/

            /*$("form").submit(function () {
                $.ajax({
                    type:"post",
                    url:"course/addCourse.do",
                    data:$("form").serialize(),
                    success:function (data) {
                        alert(data.info)
                    }
                })
                return false;
            })*/

            //监听提交
            form.on('submit(demo1)', function (data) {
                console.log(data)
                $.ajax({
                    type: "post",
                    data: $('form').serialize(),
                    url: "course/addCourse.do",
                    success: function (res) {
                        if (res.code == 0) {
                            alert("添加成功")
                            window.location.href = "courseadd.html"
                        } else {
                            alert("添加失败")
                        }
                    }

                })
                return false;
            });


            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });


        });


</script>
</body>
</html>